package web.mb;

import java.util.List;
import java.util.Set;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import metier.entities.Client;
import metier.entities.Etat;
import metier.entities.GLN;
import metier.entities.Pays;
import metier.entities.Ville;
import metier.sess.IEtatLocal;
import metier.sess.IGLNLocal;
import metier.sess.IPaysLocal;
import metier.sess.IUtilisateurLocal;
import metier.sess.IVilleLocal;



@ManagedBean
@ViewScoped
public class GLNMB {
	
	
	
	@EJB
	private IGLNLocal metiergln;
	
	@EJB 
	private IPaysLocal meteirp;
	
	@EJB
	private IEtatLocal metiere;
	
	@EJB 
	private IVilleLocal meteirv;
	
	@EJB
	private IUtilisateurLocal metieru;
	
	static private GLN gln=new GLN();
	
	static private Integer Id;
	
	static private Integer IdClient ;
	
	
	
	//utilisé 
	
	//country,state,city for contact person
		static private Integer IdS;
		
		static private Integer IdC;
		
		static private Integer IdCi;
		
		//list  country,state,city for contact person
		static private Set<Etat> listeEtat;
		static private Set<Ville> listeVille;
		
		
		
	 public GLN getGln() {
			return gln;
		}

		public void setGln(GLN gln) {
			this.gln = gln;
		}

		public Integer getId() {
			return Id;
		}

		public void setId(Integer id) {
			Id = id;
		}

		public Integer getIdClient() {
			return IdClient;
		}

		public void setIdClient(Integer idClient) {
			IdClient = idClient;
		}

		public  Integer getIdS() {
			return IdS;
		}

		public  void setIdS(Integer idS) {
			IdS = idS;
		}

		public  Integer getIdC() {
			return IdC;
		}

		public  void setIdC(Integer idC) {
			IdC = idC;
		}

		public  Integer getIdCi() {
			return IdCi;
		}

		public  void setIdCi(Integer idCi) {
			IdCi = idCi;
		}

		public  Set<Etat> getListeEtat() {
			return listeEtat;
		}

		public  void setListeEtat(Set<Etat> listeEtat) {
			GLNMB.listeEtat = listeEtat;
		}

		public  Set<Ville> getListeVille() {
			return listeVille;
		}

		public  void setListeVille(Set<Ville> listeVille) {
			GLNMB.listeVille = listeVille;
		}
		
		public List<Pays> getListPays()
		{
			return meteirp.getAllPaysActive();
		}
		//liste des utilisateur
		
		public List<Client> listeClient()
		{
			return metieru.getAllclients();
		}
		
		
		

	   public void onCountryChange() {
			 
			 
			
				 if(IdC!=0)
			        {
			        	
					 listeEtat= meteirp.getPays(IdC).getListEtat();
			        }
			        else
			        {
			        	listeEtat=null;
			        }
			
			 
			 
		        
		    }
		 
		 public void onStateChange() {
			
			 
			 
				 if(IdS!=0)
			        {
			        	
			        	listeVille=metiere.getEtat(IdS).getListVille();
			        }
			        else
			        {
			        	listeVille=null;
			        }
			 
			 
			
			   
		    }
		 
	//Ajout
		 public String Ajouter()
			{
				
				gln.setVille_GLN(meteirv.getVille(IdCi));
				gln.setClient((Client)metieru.getUtilisateur(IdClient));
				metiergln.addGLN(gln);
				
				return "ManageGLN.xhtml";
			}
		 

   //Modification
		 public String edit(Integer Id)
		 {
			 this.Id=Id;
			 gln=metiergln.getGLNe(Id);
			 IdCi=gln.getVille_GLN().getIdVille();
			 IdS=meteirv.getVille(IdCi).getEtat().getIdEtat();
			 IdC=metiere.getEtat(IdS).getPays().getIdPays();
			 
			 IdClient=gln.getClient().getIdUtilisateur();
			 
			 //liste Etat
			 listeEtat=meteirp.getPays(IdC).getListEtat();
			 //liste villes
			 listeVille=metiere.getEtat(IdS).getListVille();
			 
			 return "EditGLN.xhtml";
			 
		 }
		 
		 public String Modifier()
		 {
			    gln.setVille_GLN(meteirv.getVille(IdCi));
				gln.setClient((Client)metieru.getUtilisateur(IdClient));
				metiergln.updateGLN(gln);
				return "ManageGLN.xhtml";
		 }
		 
		 
	//suppression
		 public String Supprimer(Integer Id)
		 {
			 metiergln.deleteGLN(Id);
			 return "ss";
		 }
	
public List<GLN> listeGLN()
{
	return metiergln.getAllGLNs();
}
	
}
